﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using UI.Themes;

namespace UI
{
    public partial class Command : ObservableObject
    {
        private readonly ThemeChoose themeChoose;

        [ObservableProperty]
        private Class.SimulationTestData _QiTestData;

        [ObservableProperty]
        private DateTime dateTimeNow = DateTime.Now;

        public Command()
        {
            System.Timers.Timer timer = new System.Timers.Timer();
            timer.Interval = 1000;
            timer.Elapsed += Timer_Elapsed;
            timer.Start();


            QiTestData = new Class.SimulationTestData();
        }

        private void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
        {
            DateTimeNow = DateTime.Now;
        }

        public Command(Themes.ThemeChoose themeChoose) : this()
        {
            this.themeChoose = themeChoose;
        }


        #region 关于执行命令
        [RelayCommand]
        public void Call_Main()
        {
            MessageBox.Show("Call_Main");
        }
        [RelayCommand]
        public void Call(string cmd)
        {
            MessageBox.Show(cmd);
        }
        #endregion



        #region 想在这里用作数据绑定的数据
        [ObservableProperty]
        private Tools.AppSettings _Settings;

        public void PushData(object o)
        {
            if (o == null)
            {
                MessageBox.Show($"啥都没推送过来，干嘛呢。");
            }
            else
            {
                var t = o.GetType();
                switch (t.FullName)
                {
                    case "UI.Tools.AppSettings":
                        Settings = o as UI.Tools.AppSettings;
                        break;
                    default:
                        MessageBox.Show($"未经过确认的类型，【{t.FullName}】。");
                        break;
                }
            }
        }
        #endregion




        #region 关于页面切换

        [ObservableProperty]
        private UserControl _UserControl;

        [RelayCommand]
        public void Call_ChangePage(string pageName)
        {
            switch (pageName)
            {
                case "DataGrid":
                case "真型叶片仿真实验平台":
                    ChoosePage(pageName);
                    break;
                default:
                    MessageBox.Show(pageName);
                    break;
            }
        }

        

        private Pages.PC_UserControl_DataGrid PC_UserControl_DataGrid = null;
        private Pages.PC_UserControl_ZhenXingYePian PC_UserControl_ZhenXingYePian = null;

        private void ChoosePage(string pageName)
        {
            switch (pageName)
            {
                case "DataGrid":
                    {
                        if (PC_UserControl_DataGrid == null)
                        {
                            PC_UserControl_DataGrid = new Pages.PC_UserControl_DataGrid();
                        }
                        UserControl = PC_UserControl_DataGrid;
                    }
                    break;
                case "真型叶片仿真实验平台":
                    {
                        if (PC_UserControl_ZhenXingYePian == null)
                        {
                            PC_UserControl_ZhenXingYePian = new Pages.PC_UserControl_ZhenXingYePian();
                        }
                        UserControl = PC_UserControl_ZhenXingYePian;
                    }
                    break;
                default:
                    MessageBox.Show($"【{pageName}】未定义。");
                    break;
            }
        }
        #endregion


        #region 关于主题变换
        [RelayCommand]
        public void ChangeTheme(string themeName)
        {
            themeChoose.ChangeTheme(themeName);
        }


        #endregion

    }
}
